package com.ss.android.newmedia.a;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.webkit.DownloadListener;
import android.webkit.WebView;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONObject;

final class m implements DownloadListener {
    private final BrowserFragment a;

    m(BrowserFragment arg1) {
        this.a = arg1;
    }

    public final void onDownloadStart(String arg13, String arg14, String arg15, String arg16, long arg17) {
        JSONObject v2;
        BrowserFragment v7 = this.a;
        try {
            FragmentActivity v0_1 = v7.getActivity();
            if(v0_1 != null) {
                String v1 = null;
                if(v7.mWebview != null) {
                    v1 = v7.mWebview.getUrl();
                }

                if(v7.H <= 0 && !android.support.design.a.isTextEmpty(v1) && !v7.mBaseAppData.j(v1)) {
                    v2 = new JSONObject();
                    JSONObject v3 = new JSONObject();
                    v3.put("url", arg13);
                    v3.put("referer_url", v1);
                    v2.put("label", "browser");
                    v2.put("ext_json", v3);
                    AppUtil.reportAppDownloadBanned(((Context)v0_1), v2);
                    return;
                }

                JSONObject v5 = new JSONObject();
                v2 = new JSONObject();
                v2.put("url", arg13);
                if(!android.support.design.a.isTextEmpty(v1)) {
                    v2.put("referer_url", v1);
                }

                if(!android.support.design.a.isTextEmpty(v1) && !v1.equals(v7.y)) {
                    v2.put("init_url", v7.y);
                }

                v2.put("ad_id", v7.H);
                if(v7.H <= 0) {
                    v2.put("in_white_list", 1);
                }

                v5.put("label", "browser");
                v5.put("ext_json", v2);
                long[] v6 = new long[1];
                AlertDialog v1_1 = AppUtil.a(((Context)v0_1), v7.mBaseAppData, arg13, arg14, arg16, v5, v6);
                long v2_1 = v6[0];
                if(v2_1 >= 0 && v7.mJsObject != null) {
                    v7.mJsObject.addDownloadListener(Long.valueOf(v2_1), arg13);
                    WebView v2_2 = v7.mJsObject.getWebView();
                    if(v2_2 != null && !android.support.design.a.isTextEmpty(arg13)) {
                        v2_2.loadUrl("javascript:onGameStart(\'" + arg13 + "\')");
                    }
                }

                if(v1_1 == null) {
                    if(!v7.D) {
                        return;
                    }

                    if(v7.E) {
                        return;
                    }

                    if(((Activity)v0_1).isFinishing()) {
                        return;
                    }

                    ((Activity)v0_1).finish();
                }
                else {
                    v7.N = new k(v7, ((Activity)v0_1));
                    v1_1.setOnDismissListener(new WeakDialogListener(v7.N));
                }
            }

            return;
        }
        catch(Exception v0) {
            return;
        }
    }
}

